#include <memory>
#include <string>

#include "rclcpp/rclcpp.hpp"
#include "std_msgs/msg/string.hpp"
#include "std_srvs/srv/empty.hpp"

class ServiceServerNode : public rclcpp::Node
{
   public:
    ServiceServerNode() : Node("service_server_node")
    {
        // 创建服务端
        service_ = this->create_service<std_srvs::srv::Empty>(
            "example_service", [this](const std::shared_ptr<std_srvs::srv::Empty::Request> /*request*/,
                                      std::shared_ptr<std_srvs::srv::Empty::Response> /*response*/) {
                RCLCPP_INFO(this->get_logger(), "Service called!");
                // 这里可以添加服务逻辑
            });

        RCLCPP_INFO(this->get_logger(), "Service server node started");
    }

   private:
    rclcpp::Service<std_srvs::srv::Empty>::SharedPtr service_;
};

int main(int argc, char *argv[])
{
    rclcpp::init(argc, argv);
    rclcpp::spin(std::make_shared<ServiceServerNode>());
    rclcpp::shutdown();
    return 0;
}
